package com.juyu.miliao.api.rabbitMQ;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.juyu.miliao.common.constant.BillDetailBeansMqKey;
import com.juyu.miliao.common.constant.BillDetailIntegralMqKey;
import com.juyu.miliao.common.domain.BillDetailIntegral;
import com.juyu.miliao.common.domain.dto.BillDetailBeansDTO;
import com.juyu.miliao.common.domain.dto.BillDetailIntegralDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author xuanqicheng
 */
@Component
@Slf4j
public class BillDetailIntegralMq {
    @Autowired
    private AmqpTemplate amqpTemplate;

    @Autowired
    private ObjectMapper objectMapper;

    public void getBillDetailIntegralMq(BillDetailIntegralDTO billDetailIntegralDTO){
        try {
            if (billDetailIntegralDTO != null) {
                amqpTemplate.convertAndSend(BillDetailIntegralMqKey.EXCHANGE,
                        BillDetailIntegralMqKey.CreateBillDetailIntegralKey.ROUTING_KEY,
                        objectMapper.writeValueAsString(billDetailIntegralDTO));
            }
        }catch (Exception ex){
            log.info("添加积分账单信息放入队列失败：{}", billDetailIntegralDTO);
        }
    }
}
